package com.uvt.agenda;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import java.util.List;

public class ViewSpinnerAdapter extends ArrayAdapter {

    public ViewSpinnerAdapter(Context context, List objects) {
        super(context, R.layout.view_item_type, objects);
        setDropDownViewResource(R.layout.view_item_type);
    }

    @Override
    public View getDropDownView(int position, View convertView, ViewGroup parent) {
        final ViewHolder holder;
        if (convertView == null) {
            convertView = View.inflate(getContext(), R.layout.view_item_type, null);
            holder = new ViewHolder();
            holder.viewModeName = (TextView) convertView.findViewById(R.id.viewModeName);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        // Bind the data efficiently with the holder.
        holder.viewModeName.setText((String)getItem(position));
        return convertView;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final ViewHolder holder;
        if (convertView == null) {
            convertView = View.inflate(getContext(), R.layout.view_item_type, null);
            holder = new ViewHolder();
            holder.viewModeName = (TextView) convertView.findViewById(R.id.viewModeName);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        // Bind the data efficiently with the holder.
        holder.viewModeName.setText((String)getItem(position));

        return convertView;
    }

    /**
     *
     * Inner holder class for a single row view in the ListView
     *
     */
    static class ViewHolder {
        TextView viewModeName;
    }

}